package com.itheima.responsibility;

/**
 * @author zzw
 * @date 2025/10/25
 * @description 责任链模式（抽象处理者）
 */
public abstract class Handler {
    protected final static int NUM_ONE = 1;
    protected final static int NUM_THREE = 3;
    protected final static int NUM_SEVEN = 7;

    // 领导处理的请假天数区间
    private int numStart;
    private int numEnd;

    // 领导上面的领导
    private Handler nextHandler;

    // 设置请假天数范围
    public Handler(int numStart) {
        this.numStart = numStart;
    }

    // 设置请假天数范围
    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }

    // 设置上级领导
    public void setNextHandler(Handler handler) {
        this.nextHandler = handler;
    }

    // 提交请假条
    public final void submit(LeaveRequest leave) {
        if (this.numStart == 0) {
            return;
        }

        // 如果请假天数达到该领导的要求
        if (leave.getNum() >= this.numStart) {
            this.handleLeave(leave);
        }

        // 如果请假天数超过当前领导处理范围，并且还有上级
        if (leave.getNum() > numEnd && this.nextHandler != null) {
            this.nextHandler.submit(leave);
        } else {
            System.out.println("流程结束");
        }
    }

    // 各级领导处理请假条的方法
    public abstract void handleLeave(LeaveRequest leave);
}
